package megrez.boot.autoconfigure.aliyun.mail;

import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.aliyun.dm20151123.Client;
import com.aliyun.teaopenapi.models.Config;

import lombok.extern.slf4j.Slf4j;
import megrez.boot.autoconfigure.aliyun.ConfigAutoConfig;

/**
 * 邮件推送自动配置
 * 
 * @author Lucky Yang
 * @since 2.6.9
 */
@Slf4j
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(Client.class)
@AutoConfigureBefore({ ConfigAutoConfig.class })
@EnableConfigurationProperties({ MailProperties.class })
public class MailAutoConfig {

    @Bean
    public Client client(Config config) throws Exception {
        log.info("Initializing aliyun mail client");
        return new Client(config);
    }

    @Bean
    public MailSenderClient mailSenderClient(Client client, MailProperties properties) {
        return new MailSenderClient(client, properties);
    }
}
